package jdk;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that Rasta01 rotates its gun per its specified strategy.
 * @author D. Korse
 */
public class TestRasta01RotatesGun extends RobotTestBed {
  
  /** Initialized to zero, checking if gun turns during the test case. */
  double priorGunPos = 0;
  boolean gunRotated = false;
  
  
  /**
   * Specifies that SittingDuck and Rasta01 are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,jdk.Rasta01";
  }
  
  /**
   * This test runs for 1 round.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * After each turn, check to see if gun heading is changed.  If so, set the corresponding flag.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double gunPos = robot.getGunHeading();
    
    //Checks to see if gun turns during test case
    if (gunPos != priorGunPos) {
      gunRotated = true;
      priorGunPos = gunPos;
    }

  }
  
  /**
   * After the battle, check to see that the gun rotated. 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Gun Rotated", gunRotated);
  }

}
